//
//  DataHandle.m
//  UI11_Contact
//
//  Created by dllo on 15/11/23.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "DataHandle.h"
#import "Student.h"

@implementation DataHandle

// 保证不同位置不同文件调用都访问同一块空间
+ (instancetype)shareData
{
    static DataHandle *dataH = nil;
    
    if (nil == dataH) {
        dataH = [[DataHandle alloc] init];
        [dataH getData];
    }
    return dataH;
    
}

// 获取数据
- (void)getData
{
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"HW" ofType:@"plist"];
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
    
    self.stuDic = [NSMutableDictionary dictionary];
    
    
    for (NSString *key in dic) {
        
        NSMutableArray *arr = [NSMutableArray array];
        for (NSMutableDictionary *tempDic in [dic objectForKey:key]) {
            
            Student *stu = [[Student alloc] init];
            [stu setValuesForKeysWithDictionary:tempDic];
            [arr addObject:stu];
            [stu release];
        }
        [self.stuDic setObject:arr forKey:key];
    }
    // 排序
    self.stuKeys = [NSMutableArray arrayWithArray:self.stuDic.allKeys];
    [self.stuKeys sortUsingSelector:@selector(compare:)];
    
}


@end
